home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / termCapture.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  6KB  |  318 lines

  1. /*
  2. **    termCapture.c
  3. **
  4. **    File and printer capture support routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Capture(APTR Buffer,LONG Size):
  13.      *
  14.      *    Send the buffer contents to the display/disk capture.
  15.      */
  16.  
  17. VOID __regargs
  18. Capture(APTR Buffer,LONG Size)
  19. {
  20.         /* Send the filtered data to the capture file. */
  21.  
  22.     if(Config -> CaptureConfig -> CaptureFilterMode)
  23.         CaptureToFile(Buffer,Size);
  24.  
  25.         /* Store data in the log book. */
  26.  
  27.     if(!BufferFrozen)
  28.         StoreBuffer(Buffer,Size);
  29.  
  30.         /* Send the buffer to the printer. */
  31.  
  32.     if(PrinterCapture && Size)
  33.     {
  34.         if(FWrite(PrinterCapture,Buffer,Size,1) != 1)
  35.         {
  36.             BlockWindows();
  37.  
  38.             if(!MyEasyRequest(Window,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_CONSOLE_IGNORE_CLOSE_PRINTER_TXT)))
  39.             {
  40.                 Close(PrinterCapture);
  41.  
  42.                 CheckItem(MEN_CAPTURE_TO_PRINTER,FALSE);
  43.  
  44.                 PrinterCapture = NULL;
  45.  
  46.                 ConOutputUpdate();
  47.             }
  48.  
  49.             ReleaseWindows();
  50.         }
  51.     }
  52. }
  53.  
  54.     /* ClosePrinterCapture(BYTE Force):
  55.      *
  56.      *    Closes printer capture file.
  57.      */
  58.  
  59. VOID
  60. ClosePrinterCapture(BYTE Force)
  61. {
  62.     if(PrinterCapture)
  63.     {
  64.         if(ControllerActive && StandardPrinterCapture && !Force)
  65.             FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_TERMINAL_TRANSCRIPT_ENDING_TXT));
  66.  
  67.         if(Force)
  68.         {
  69.             Close(PrinterCapture);
  70.  
  71.             CheckItem(MEN_CAPTURE_TO_PRINTER,FALSE);
  72.  
  73.             PrinterCapture = NULL;
  74.  
  75.             ConOutputUpdate();
  76.  
  77.             StandardPrinterCapture = FALSE;
  78.         }
  79.     }
  80.  
  81.     ControllerActive = FALSE;
  82.  
  83.     ConOutputUpdate();
  84. }
  85.  
  86.     /* OpenPrinterCapture(BYTE Controller):
  87.      *
  88.      *    Opens printer capture file.
  89.      */
  90.  
  91. BYTE
  92. OpenPrinterCapture(BYTE Controller)
  93. {
  94.     if(PrinterCapture)
  95.     {
  96.         if(Controller && !ControllerActive)
  97.         {
  98.             ControllerActive = TRUE;
  99.  
  100.             ConOutputUpdate();
  101.  
  102.             FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_TERMINAL_TRANSCRIPT_FOLLOWS_TXT));
  103.         }
  104.  
  105.         return(TRUE);
  106.     }
  107.     else
  108.     {
  109.         if(PrinterCapture = Open("PRT:",MODE_NEWFILE))
  110.             CheckItem(MEN_CAPTURE_TO_PRINTER,TRUE);
  111.         else
  112.         {
  113.             CheckItem(MEN_CAPTURE_TO_PRINTER,FALSE);
  114.  
  115.             BlockWindows();
  116.  
  117.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_ERROR_OPENING_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),"PRT:");
  118.  
  119.             ReleaseWindows();
  120.         }
  121.  
  122.         if(Controller)
  123.         {
  124.             ControllerActive    = TRUE;
  125.             StandardPrinterCapture    = FALSE;
  126.         }
  127.         else
  128.         {
  129.             StandardPrinterCapture = FALSE;
  130.  
  131.             if(ControllerActive)
  132.                 FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_USER_TERMINAL_TRANSCRIPT_FOLLOWS_TXT));
  133.         }
  134.  
  135.         ConOutputUpdate();
  136.  
  137.         if(PrinterCapture)
  138.             return(TRUE);
  139.         else
  140.             return(FALSE);
  141.     }
  142. }
  143.  
  144.     /* CloseFileCapture():
  145.      *
  146.      *    Close the capture file.
  147.      */
  148.  
  149. VOID
  150. CloseFileCapture()
  151. {
  152.     if(FileCapture)
  153.     {
  154.         BufferClose(FileCapture);
  155.  
  156.         FileCapture = NULL;
  157.  
  158.         if(!GetFileSize(CaptureName))
  159.             DeleteFile(CaptureName);
  160.         else
  161.         {
  162.             AddProtection(CaptureName,FIBF_EXECUTE);
  163.  
  164.             if(Config -> MiscConfig -> CreateIcons)
  165.                 AddIcon(CaptureName,FILETYPE_TEXT,FALSE);
  166.         }
  167.     }
  168.  
  169.     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  170.  
  171.     ConOutputUpdate();
  172. }
  173.  
  174.     /* OpenFileCapture():
  175.      *
  176.      *    Open a capture file.
  177.      */
  178.  
  179. BYTE
  180. OpenFileCapture()
  181. {
  182.     struct FileRequester    *FileRequest;
  183.     UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  184.                 *DummyChar;
  185.     BYTE             Aborted = FALSE;
  186.  
  187.     CloseFileCapture();
  188.  
  189.     BlockWindows();
  190.  
  191.     if(!CaptureName[0])
  192.     {
  193.         strcpy(CaptureName,Config -> CaptureConfig -> CapturePath);
  194.  
  195.         if(!AddPart(CaptureName,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT),MAX_FILENAME_LENGTH))
  196.             CaptureName[0] = 0;
  197.     }
  198.  
  199.     strcpy(DummyBuffer,CaptureName);
  200.  
  201.     DummyChar = PathPart(DummyBuffer);
  202.  
  203.     *DummyChar = 0;
  204.  
  205.     if(FileRequest = GetFile(LocaleString(MSG_TERMMAIN_CAPTURE_TO_DISK_TXT),DummyBuffer,FilePart(CaptureName),DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_OPEN_TXT),FALSE))
  206.     {
  207.         if(GetFileSize(DummyBuffer))
  208.         {
  209.             switch(MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FILE_ALREADY_EXISTS_TXT),LocaleString(MSG_GLOBAL_CREATE_APPEND_CANCEL_TXT),DummyBuffer))
  210.             {
  211.                 case 1:
  212.  
  213.                     FileCapture = BufferOpen(DummyBuffer,"w");
  214.                     break;
  215.  
  216.                 case 2:
  217.  
  218.                     FileCapture = BufferOpen(DummyBuffer,"a");
  219.                     break;
  220.  
  221.                 case 0:
  222.  
  223.                     FileCapture = NULL;
  224.  
  225.                     Aborted = TRUE;
  226.  
  227.                     break;
  228.             }
  229.         }
  230.         else
  231.             FileCapture = BufferOpen(DummyBuffer,"w");
  232.  
  233.         if(!Aborted)
  234.         {
  235.             if(!FileCapture)
  236.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_ERROR_OPENING_FILE_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  237.             else
  238.                 strcpy(CaptureName,DummyBuffer);
  239.         }
  240.  
  241.         FreeAslRequest(FileRequest);
  242.     }
  243.  
  244.     if(FileCapture)
  245.         CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  246.     else
  247.         CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  248.  
  249.     ConOutputUpdate();
  250.  
  251.     ReleaseWindows();
  252.  
  253.     if(FileCapture)
  254.         return(TRUE);
  255.     else
  256.         return(FALSE);
  257. }
  258.  
  259.     /* CaptureToFile(APTR Buffer,LONG Size):
  260.      *
  261.      *    Send data to the capture file.
  262.      */
  263.  
  264. VOID __regargs
  265. CaptureToFile(APTR Buffer,LONG Size)
  266. {
  267.     if(FileCapture && Size)
  268.     {
  269.         if(BufferWrite(FileCapture,Buffer,Size) != Size)
  270.         {
  271.             BlockWindows();
  272.  
  273.                 /* We had an error writing to the file. */
  274.  
  275.             switch(MyEasyRequest(NULL,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_CAPTURE_FILE_TXT),LocaleString(MSG_CONSOLE_IGNORE_DISCARD_CLOSE_TXT),CaptureName))
  276.             {
  277.                 case 1:
  278.  
  279.                     BufferClose(FileCapture);
  280.  
  281.                     DeleteFile(CaptureName);
  282.  
  283.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  284.  
  285.                     FileCapture = NULL;
  286.  
  287.                     ConOutputUpdate();
  288.  
  289.                     break;
  290.  
  291.                 case 2:
  292.  
  293.                     BufferClose(FileCapture);
  294.  
  295.                     CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  296.  
  297.                     FileCapture = NULL;
  298.  
  299.                     if(!GetFileSize(CaptureName))
  300.                         DeleteFile(CaptureName);
  301.                     else
  302.                     {
  303.                         AddProtection(CaptureName,FIBF_EXECUTE);
  304.  
  305.                         if(Config -> MiscConfig -> CreateIcons)
  306.                             AddIcon(CaptureName,FILETYPE_TEXT,FALSE);
  307.                     }
  308.  
  309.                     ConOutputUpdate();
  310.  
  311.                     break;
  312.             }
  313.  
  314.             ReleaseWindows();
  315.         }
  316.     }
  317. }
  318.